'''
design
'''

###################################################################################
def singleton(cls):
	'''
	Make a class to be a singleton
	'''
	assert isinstance(cls, type), 'cls must be an class'

	instances	= {}
	def __getinstance(*args, **kwds):
		if cls not in instances:
			instances[cls]	= cls(*args, **kwds)
		return instances[cls]
	return __getinstance

###################################################################################
def costtime(f):
	'''
	add an costtime attribute when run f(*args)
	'''
	import time
	def newf(*args):
		start			= time.time()
		f(*args)
		newf.costtime	= time.time() - start
	
	newf.__name__		= f.__name__
	newf.costtime		= 0
	return newf
